home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4654 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  41 lines

  1. Path: camelot.ccs.neu.edu!bhardwaj
  2. From: bhardwaj@ccs.neu.edu (saurabh bhardwaj)
  3. Newsgroups: comp.lang.c++
  4. Subject: Comparing Struct elements
  5. Date: 31 Jan 1996 15:30:50 GMT
  6. Organization: College of Computer Science, Northeastern University.
  7. Message-ID: <4eo1va$s6k@camelot.ccs.neu.edu>
  8. NNTP-Posting-Host: maunakea.ccs.neu.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hello,
  12.  
  13. I've been trying to compare structure elements using the if Statement.  Here
  14. is the code:
  15.  
  16.  
  17. double NumericVal(ClassRec& LetGrade){
  18.  
  19. cout << "assgning struct member usin . " << LetGrade.
  20. Grade << '\n';
  21. if(LetGrade.Grade == "A") return(4.000);
  22. else if(LetGrade.Grade == "A-") return(3.666);
  23. else if(LetGrade.Grade == "B+") return(3.333);
  24. else return 0;
  25. }
  26.  
  27. where LetGrade is the following struct:
  28.  
  29. struct ClassRec {
  30.      char Grade[3];
  31.      int   QH;
  32.      char Name[10];
  33.      };
  34.  
  35. I can't seem to compare the elements of the Grade[3] with "A" or "A-" or "B+"
  36. The function invariable returns 0.  I've also tried using the -> operator.  It
  37. doesn't work either!!!   Anyone know why???  I'll appreciate any help.
  38.  
  39.                         thanks
  40.                         saurabh
  41.